package com.tangdi.Action;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.tangdi.Dao.impl.userDaoImpl;

public class loginServlet extends HttpServlet {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private Logger logger = Logger.getLogger(loginServlet.class);

	public loginServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doPost(request,response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html");
		request.setCharacterEncoding("utf-8");
		
		String userP=request.getParameter("user");		
		String name=request.getParameter("name");

		System.out.println(userP);
		System.out.println(name);
		String password=request.getParameter("password");
		System.out.println(password);
		
		userDaoImpl dao=new userDaoImpl();
		HttpSession session=request.getSession();
		
		/*//人事部人员登陆
		if(userP.equals("personnel")){
			if(dao.checkUser(name, password)){
				session.setAttribute("recruiterName",name);
				response.sendRedirect("header.jsp");
			}
			else{
				request.setAttribute("info","用户名或密码错误！");
				request.getRequestDispatcher("login.jsp").forward(request,response);
			}
		}*/
		//管理员登录
		/*else if(userP.equals("admin")){*/

		logger.info("登录成功");
		if(dao.checkAdmin(name, password)){
			session.setAttribute("recruiterName","admin");
			response.sendRedirect("header.jsp");
			}else{
				request.setAttribute("info","用户名或密码错误！");
				logger.info("登录失败，用户名或密码错误！");
				request.getRequestDispatcher("login.jsp").forward(request,response);
		}

		}
		

	public void init() throws ServletException {
		// Put your code here
	}

}
